package com.zx.my.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zx.my.entity.MyStudy;
import com.zx.my.model.StudyChartDto;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface MyStudyMapper extends BaseMapper<MyStudy> {

    @Select("SELECT  " +
            "	DATE_FORMAT(study_date, '%Y-%m-%d') AS 'date', " +
            "	ROUND( SUM(study_time) / 3600, 2) AS 'time' " +
            "FROM my_study WHERE begin_time BETWEEN #{begin, jdbcType=TIMESTAMP} AND #{end, jdbcType=TIMESTAMP} " +
            "GROUP BY 1 " +
            "ORDER BY 1 ASC ")
    List<StudyChartDto> getDayChart(@Param("begin") Date begin, @Param("end") Date end);

    @Select("SELECT  " +
            "	DATE_FORMAT(study_date, '%Y-%m') AS 'date', " +
            "	ROUND( SUM(study_time) / 3600, 2) AS 'time' " +
            "FROM my_study WHERE begin_time BETWEEN #{begin, jdbcType=TIMESTAMP} AND #{end, jdbcType=TIMESTAMP} " +
            "GROUP BY 1 " +
            "ORDER BY 1 ASC ")
    List<StudyChartDto> getMonthChart(@Param("begin") Date begin, @Param("end") Date end);

}
